package stack_queue;

import dome3.LinkedList;

import java.util.List;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description: 链栈--单链表
 * User: 王圆豪
 * Date: 2024-08-12
 * Time: 16:39
 */
public class List_stack {
    ListNode head;

    static class ListNode{
        ListNode next;
        int a;
    }

    public void push(ListNode l) {
        if (l == null) {
            return;
        }
        l.next = head;
        head = l;
    }

    public ListNode pop(){
        ListNode k = head;
        try {
            if (head == null) {
                throw new EmptyException();
            }
            head = head.next;
        }catch (EmptyException o){
            o.printStackTrace();
        }
        return k;
    }

    public ListNode peek() {
        return head;
    }

    public boolean isEmpty() {
        return head == null;
    }
}
